#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START perl
# depends: gdbm
# depends: libdb4.7
# depends: libxcrypt
# depends: zlib

# XXX: guess this from the source
perlver=5.34

reset_mtime perl perl/Configure
rm -rf build/perl
cp -a perl build/
cd build/perl


env \
	ac_cv_buggy_getaddrinfo=no \
	ac_cv_file__dev_ptmx=yes \
	ac_cv_file__dev_ptc=no \
./configure \
	--target=${TARGET} \
	-Duse64bitint \
	-Dusethreads -Duseithreads -Duselargefiles \
	-DDEBUGGING=maybe \
	-Duseshrplib \
	-Dlibperl="libperl-${perlver}.so" \
	-Dprefix=$prefix \
	-Dprivlib=$prefix/share/perl5 \
	-Darchlib=$prefix/$target_libdir/perl5 \
	-Dvendorprefix=$prefix \
	-Dvendorlib=$prefix/share/perl5 \
	-Dvendorarch=$prefix/$target_libdir/perl5 \
	-Dsiteprefix=$prefix/local \
	-Dsiteplib=$prefix/local/share/perl5 \
	-Dsitearch=$prefix/local/$target_libdir/perl5 \
	-Dotherlibdirs=/etc/perl5:$prefix/$target_libdir/perl5/vendor_perl \
	-Dinc_version_list=none \
	-Dpager="$prefix/bin/less -isR" \
	-Dman1dir=$prefix/share/man/man1 \
	-Dman3dir=none \
	-Dcf_by='boringlinux' \
	-Dcf_email='example@example.com' \
	-Dmyhostname='localhost' \
	-Dperladmin='root@localhost'

make -j${JOBS}
make -j${JOBS} install.perl DESTDIR=`pwd`/inst

mv "inst${prefix}/$target_libdir/perl5/CORE/libperl-${perlver}.so" "inst${prefix}/${target_libdir}"
ln -s "libperl-${perlver}.so" "inst${prefix}/$target_libdir/libperl.so"
ln -sr "inst${prefix}/$target_libdir/libperl-${perlver}.so" "inst${prefix}/$target_libdir/perl5/CORE/libperl-${perlver}.so" 
ln -sr "inst${prefix}/$target_libdir/libperl-${perlver}.so" "inst${prefix}/$target_libdir/perl5/CORE/libperl.so" 
rsync -avH "inst${prefix}/" "${stage}${prefix}/"
cd ../..
rm -rf build/perl

# RECIPE END perl
